<?php

namespace Addons\GiveReward;
use Common\Controller\Addon;
use Admin\Controller\Addones;


/**
 * 打赏插件插件
 * @author abby_boy
 */

    class GiveRewardAddon extends Addon{

        public $info = array(
            'name'=>'GiveReward',
            'title'=>'打赏插件',
            'description'=>'打赏微博，评论，帖子',
            'status'=>1,
            'author'=>'abby_boy',
            'version'=>'1.0.0'
        );

        public function install(){

            $prefix = C("DB_PREFIX");
            $model = D();
            $model->execute("DELETE FROM `{$prefix}hooks`  WHERE `name` ='GiveReward';");
            $model->execute("INSERT INTO `{$prefix}hooks` ( `name`, `description`, `type`, `update_time`, `addons`) VALUES
('giveReward', '打赏微博，帖子，评论', 1, 1451281540, 'GiveReward');");


            $model->execute("DROP TABLE IF EXISTS `{$prefix}give_reward`");
            $model->execute("
CREATE TABLE IF NOT EXISTS `{$prefix}give_reward` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `url` varchar(500) NOT NULL,
  `uid` int(11) NOT NULL,
  `field` int(11) NOT NULL,
  `num` double DEFAULT '0',
  `to_uid` int(11) NOT NULL,
  `create_time` int(11) NOT NULL,
  `hook_type` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
");


            $model->execute("
INSERT INTO `{$prefix}action` ( `name`, `title`, `remark`, `rule`, `log`, `type`, `status`, `update_time`, `module`) VALUES
( 'give_reward', '打赏', '打赏了一个人', '', '[user|get_nickname]在[time|time_format]打赏了一个信息：[record|intval]', 1, 1, 1451028409, ''),
( 'get_reward', '得到打赏', '获得了打赏', '', '[user|get_nickname]在[time|time_format]获得了一个打赏：[record|intval]', 1, 1, 1451028409, '');
");
            return true;
        }

        public function uninstall(){
            $prefix = C("DB_PREFIX");
            D()->execute("DROP TABLE IF EXISTS `{$prefix}give_reward`");
            return true;
        }

        //实现的giveReward钩子方法
        public function giveReward($param){

            $this->assign('param', $param);
            $url=T('Addons://GiveReward@giveReward/givereward');
            $this->display($url);

        }

    }